package com.danny.componenttest

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.View
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.callback.NavigationCallback
import com.alibaba.android.arouter.launcher.ARouter
import com.danny.provider.RouterPath
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.toast

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }

    fun login(view: View) {
//        ARouter.getInstance().build("/account/login").navigation()
        ARouter.getInstance().build(RouterPath.Login.PATH_LOGIN).navigation()
    }

    fun share(view: View) {
//        ARouter.getInstance().build("/share/Share")
        ARouter.getInstance().build(RouterPath.Share.PATH_SHARE)
                .withString("share_content","分享数据到微博").navigation(this, object : NavigationCallback{
                    override fun onLost(postcard: Postcard?) {
                        println("onLost")
                    }

                    override fun onFound(postcard: Postcard?) {
                        println("onFound")
                    }

                    override fun onInterrupt(postcard: Postcard?) {
                        println("onInterrupt")
                        runOnUiThread { toast("请先登录") }
                    }

                    override fun onArrival(postcard: Postcard?) {
                        println("onArrival")
                    }

                })
    }

    fun fragment(view: View) {
        startActivity<FragmentActivity>()
    }
}
